﻿using Forum.Model.Entity;
using Forum.Repository.Interface;
using Forum.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Forum.Service.Service
{
    public class FeaturedPostService : IFeaturedPostService
    {
        private readonly IAppRepository<Post> _postRepo;
        private readonly IAppRepository<FeaturedPost> _featuredPostRepo;

        public FeaturedPostService(IAppRepository<FeaturedPost> featuredPostRepo, IAppRepository<Post> postRepo)
        {
            _featuredPostRepo = featuredPostRepo;
            _postRepo = postRepo;
        }

        public List<FeaturedPost> GetList()
        {
            return _featuredPostRepo.SugarQueryable.Includes(a => a.Post, p => p.Category).ToList();
        }

        public FeaturedPost Get(int id)
        {
            return _featuredPostRepo.SugarQueryable.Where(a => a.Id == id)
                                    .Includes(a => a.Post).First();
        }


        public bool Insert(FeaturedPost post)
        {
            return _featuredPostRepo.Insert(post);
        }

        public bool Delete(FeaturedPost post)
        {
            return _featuredPostRepo.Delete(post);
        }
    }
}
